var t = getApp(), e = require("../../utils/qrcode.js");

Page({
    data: {
        albumList: {},
        imgUrls: [],
        indicatorDots: !1,
        autoplay: !1,
        newImgArr: [],
        isMore: !0,
        url: t.server + "/static/h5/static/book/index.html?id=",
        isQrcode: !0,
        inint: !1,
        maskHidden: !0,
        imagePath: "",
        placeholder: "http://wxapp-union.com",
        server: t.server,
        serverUrl: t.serverUrl
    },
    onLoad: function(e) {
        var a = this;
        t.request({
            url: t.server + "/picApi/factoryAlbumList",
            method: "POST",
            data: {
                token: t.token
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                console.log(t.data), a.setData({
                    albumList: t.data.result.albums
                });
            }
        });
    },
    onReady: function() {
        var t = this.setCanvasSize(), e = this.data.placeholder;
        this.createQrCode(e, "mycanvas", t.w, t.h);
    },
    onShow: function() {
        wx.setNavigationBarTitle({
            title: "画册"
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    toDetail: function(e) {
        var a = this;
        this.data.newImgArr = [], t.request({
            url: t.server + "/picApi/factoryAlbumInfo",
            method: "POST",
            data: {
                token: t.token,
                id: e.target.dataset.id
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(e) {
                console.log(e.data), a.data.infoList = e.data.result.albums;
                for (var i = 0; i < e.data.result.album.pic.length; i++) a.data.newImgArr.push(t.server + e.data.result.album.pic[i].url);
                console.log(a.data.newImgArr), wx.previewImage({
                    current: "",
                    urls: a.data.newImgArr,
                    success: function(t) {}
                });
            }
        });
    },
    moreTap: function(t) {
        console.log(t.target.dataset.index), this.setData({
            isMore: !1,
            initmore: t.target.dataset.index
        });
    },
    lookQrcode: function(e) {
        this.data.url = t.server + "/static/h5/static/book/index.html?id=", console.log(e), 
        this.setData({
            isQrcode: e.target.dataset.index,
            inint: !0
        });
        var a = this;
        console.log(e.currentTarget.dataset, e.target.dataset);
        var i = this.data.url + e.currentTarget.dataset.id + "&width=" + e.target.dataset.width + "&height=" + e.target.dataset.height + "&v=" + new Date().getTime();
        a.setData({
            url: i,
            maskHidden: !1
        }), wx.showToast({
            title: "生成中...",
            icon: "loading",
            duration: 2e3
        });
        var n = setTimeout(function() {
            wx.hideToast();
            var t = a.setCanvasSize();
            a.createQrCode(i, "mycanvas", t.w, t.h), a.setData({
                maskHidden: !0
            }), clearTimeout(n);
        }, 2e3);
    },
    copy: function(t) {
        wx.setClipboardData({
            data: this.data.url,
            success: function() {
                wx.showToast({
                    title: "复制成功",
                    icon: "success",
                    duration: 2e3
                });
            }
        });
    },
    setCanvasSize: function() {
        var t = {};
        try {
            var e = wx.getSystemInfoSync().windowWidth / 1.875, a = e;
            t.w = e, t.h = a;
        } catch (t) {
            console.log("获取设备信息失败" + t);
        }
        return t;
    },
    createQrCode: function(t, a, i, n) {
        e.qrApi.draw(t, a, i, n);
    },
    canvasToTempImage: function() {
        var t = this;
        wx.canvasToTempFilePath({
            canvasId: "mycanvas",
            success: function(e) {
                var a = e.tempFilePath;
                console.log("********" + a), t.setData({
                    imagePath: a
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    previewImg: function(t) {
        wx.canvasToTempFilePath({
            canvasId: "mycanvas",
            success: function(t) {
                console.log(t.tempFilePath);
                t.tempFilePath;
                wx.previewImage({});
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    cancel: function() {
        this.setData({
            inint: !1,
            isMore: !0
        });
    },
    toPlay: function(t) {
        wx.navigateTo({
            url: "/pages/album/detail/detail?id=" + t.target.dataset.id + "&width=" + t.target.dataset.width + "&height=" + t.target.dataset.height
        });
    }
});